package sk.tramtatiri.data.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import javax.persistence.TypedQuery;

import org.springframework.orm.jpa.JpaCallback;
import org.springframework.transaction.annotation.Transactional;

import sk.tramtatiri.data.dao.interfaces.DietDao;
import sk.tramtatiri.data.dataobjects.Diet;

public class DietDaoJPAImp extends AbstractDaoJPAImpl<Diet> implements DietDao{

	public DietDaoJPAImp() {
		super(Diet.class);
	}

	@Transactional
	public List<Diet> findAll() {
		return getJpaTemplate().execute(new JpaCallback<List<Diet>>() {
			public List<Diet> doInJpa(EntityManager em) throws PersistenceException {
				TypedQuery<Diet> query = em.createQuery("select d from Diet d", Diet.class);
				return query.getResultList();
			}
		});
	}

	@Transactional
	public int countAll() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Transactional
	public Diet findName(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@Transactional
	public void delete(Diet o) {
		Diet d = getJpaTemplate().find(Diet.class, o.getId());
		getJpaTemplate().remove(d);
	}

}
